#include "DB.h"

DB::DB() //: bufferManager(SingleBufferManager(DB_FILE.c_str(), 10)), segmentInventory(DB_FILE_SIZE, bufferManager), segmentManager(segmentInventory)
{
    this->bufferManager = new SingleBufferManager(DB_FILE.c_str(), 10);
    this->segmentInventory = new SegmentInventory(DB_FILE_SIZE, *this->bufferManager);
    this->segmentManager = new SegmentManager(*this->segmentInventory);
}

DB& DB::getDB()
{
    static DB instance;
    return instance;
}

void DB::destroyDB()
{
    delete this->segmentManager;
    delete this->segmentInventory;
    delete this->bufferManager;
    this->segmentManager = NULL;
    this->segmentInventory = NULL;
    this->bufferManager = NULL;
}

BufferManager& DB::getBufferManager()
{
    return *bufferManager;
}

SegmentManager& DB::getSegmentManager()
{
    return *segmentManager;
}

SegmentInventory& DB::getSegmentInventory()
{
    return *segmentInventory;
}

DB::~DB()
{
    delete this->segmentManager;
    delete this->segmentInventory;
    delete this->bufferManager;
}
